#ifndef GFX_IMAGE_H
#define GFX_IMAGE_H

#ifndef UGLY_HACK_FOR_THOSE_WHO_DONT_KNOW_HOWTO_INSTALL_SDL
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

#include "gfx_core.h"


//-----------------------------------------------------------------------------
// Image
//-----------------------------------------------------------------------------


/**
 * \brief Image structure.
 */
typedef struct
{
    /// \brief Width and height of the image in pixels.
    int width, height;

    /// \brief Number of row and columns.
    int rows, columns;

    /// \brief Drawing offset.
    int xoffset, yoffset;

    /// \brief Name of the image.
    char *name;

    /// \brief Private data.
    void *image;

} GFX_Image;

void gfx_image_init(void);
void gfx_image_exit(void);

/**
 * \brief Load a image to the image collection.
 * \param filename Path to the image
 * \return 0 on success, -1 on failure.
 */
int gfx_image_load(const char *filename);

/**
 * \brief Unload a image from the image collection.
 * \param name Name of the image
 * \return 0 on success, -1 on failure.
 */
int gfx_image_unload(const char *name);

/**
 * \brief Get an image from the image collection.
 * \param name Name of the image
 * \return Pointer to the GFX_Image, or 0 if not found.
 */
GFX_Image* gfx_image_get(const char *name);

/**
 * \brief Iterate through all loaded images.
 * \param data Iterator
 * \return Current key-value pair.
 * \see map_iterate()
 */
MapPair* gfx_image_iterator(MapPair *pair);

/**
 * \brief Macro helper to iterate through all images.
 */
#define GFX_IMAGE_ITERATE(i) for(MapPair *i = gfx_image_iterator(0); i; i = gfx_image_iterator(i))

#endif
